package com.triptogether.receivers;

import android.content.Context;
import android.content.Intent;

import com.triptogether.utils.db.DBManager;
import com.triptogether.utils.db.models.Trip;

public class TripCreatedReceiver extends DBObjectCreatedReceiver {

	public static final String INTENT_FILTER_ACTION_TRIP_CREATED = DBManager.class.getName() + "trip.created";
	public static final String INTENT_TRIP_CREATE_KEY_TRIP_ID = "tripId";
	
	public TripCreatedReceiver(DBObjectCreatedListener listener) {
		registerToDbObejctCreatedReceiverListener(listener);
    }
	
	@Override
	public void onReceive(Context context, Intent intent) {
		// Get the message id from the intent
		long tripId = intent.getLongExtra(TripCreatedReceiver.INTENT_TRIP_CREATE_KEY_TRIP_ID, Long.MIN_VALUE);
		
		if (tripId != Long.MIN_VALUE) {
			// Get the new trip from the DB
			Trip newTrip = DBManager.getInstance(context).findTripById(tripId);
			
			onDbObjectCreated(newTrip);
		}
	}

}
